<?php
session_start();
require_once('../scripts/db.php');
require_once('includes/twitterOAuth.php');
include("includes/functions.php");

if ($_POST) {

$user = $_POST['username'];
$postcode = $_POST['txtPostcode'];
$area = $_POST['radAlertAreaSize'];

if (!IsPostcode($postcode)) { $error[] = "<li>Please enter a valid UK Postcode</li>"; }
if (strlen($user) == 0) { $error[] = "<li>You must enter your Twitter username</li>"; }
if (!checkuser($user)) { $error[] = "<li>Username not found</li>"; }
if (strlen($postcode) == 0) { $error[] = "<li>You must enter your postcode</li>"; }

if (count($error) == 0) {
$postcode = str_replace(" ", "", $postcode);

$query = "INSERT INTO `papptweet` ( `id` , `username` , `postcode`, `area`, `lastchecked` ) VALUES (NULL , '$user', '$postcode', '$area', CURDATE() )";
mysql_query($query) or die(mysql_error());

$url = "http://twitter.com/friendships/create/". $user .".json?follow=true";

$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

if($_POST['autofollow'] == 1) {

$consumer_key = 'RgNXfJoBbdlQPCMoQ6CDeQ';
$consumer_secret = 'OAgdkJJpv8j7zpr8OdlCI2JLfMt363wsEUAG2Er3g';

    /* Create TwitterOAuth object with app key/secret */
    $to = new TwitterOAuth($consumer_key, $consumer_secret);
    /* Request tokens from twitter */
    $tok = $to->getRequestToken();

    /* Save tokens for later */
    $_SESSION['oauth_request_token'] = $token = $tok['oauth_token'];
    $_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret'];
    $_SESSION['oauth_state'] = "start";

    /* Build the authorization URL */
    $request_link = $to->getAuthorizeURL($token);

    /* Build link that gets user to twitter to authorize the app */
	header("Location: $request_link");
} else {
header("Location: thanks.php");
}

}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>TwitterPlan | Get local planning applications sent directly to you via a Twitter DM (direct message)</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 7]>
<style type="text/css">
button {
	margin: -4em 0 0 -2em !important;
	}
</style>
<![endif]-->	

<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript">

$(document).ready(function() {	

	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(10);	
		$('#mask').fadeTo("slow",0.45);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(10); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask, .window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});

</script>

</head>

<body>
<div id="wrapper">
<div id="main">
<img src="images/logo.jpg" alt="TwittertPlan Alpha" width="315" height="62" />
<img src="images/bird.jpg" alt="TwitterPlan Mascot" width="228" height="238" id="mascot" /><p class="intro">Get local planning applications sent directly to you via a Twitter DM (direct message).<br /><a href="#area" name="modal">Is my area covered?</a></p>
<?php
if (count($error) > 0){
?>
<p>There were <?php echo count($error); ?> error(s):</p>
<ul>
<?php 
foreach ($error as $error) {
echo $error;
}
?>
</ul>
<?php
}
?>
<form action="" method="post">
   <ul id="ulSignup" class="form nobullets">

        <li id="liEmail">
            <label for="username"><span class="number">1.</span> Enter your Twitter username </label>
            <input class="textbox" id="username" name="username" value="" type="text">
        </li>
        <li id="liPostcode">
            <label for="txtPostcode"><span class="number">2.</span> Enter your postcode</label>

            <input class="textbox" id="txtPostcode" name="txtPostcode" type="text">
            <small>e.g. SW9 8JX</small>        </li>
        <li id="liAlertArea">
            <p id="pAlertArea"><span class="number">3.</span> Choose what size area would you like to receive alerts for</p>
            <fieldset>
                <ul id="ulAlertArea" class="form nobullets">

                  <li>
                        <input id="radAlertAreaSize_street" name="radAlertAreaSize" value="s" type="radio">
                    <label for="radAlertAreaSize_street">My street (approximately 200 m)</label></li>
                    <li>
                        <input id="radAlertAreaSize_neihgbourhood" name="radAlertAreaSize" value="m" checked="checked" type="radio">                                    
                        <label for="radAlertAreaSize_neihgbourhood">My neighbourhood  (approximately 800 m)</label>
                    </li>
                    <li>
                        <input id="radAlertAreaSize_town" name="radAlertAreaSize" value="l" type="radio">                                    
                        <label for="radAlertAreaSize_town">Wider area  (approximately 2000 m)</label>
                    </li>
                </ul>
            </fieldset>
        </li>       
	<li id="step4">
		<label for="autofollow"><span class="number">4.</span> Automatically follow <a href="http://twitter.com/planbot">Twitterplan</a>?<br /><span class="exp"><a href="#dialog" name="modal">What does this mean?</a></span></label> 
		<input type="checkbox" name="autofollow" value="1" id="autofollow" checked="checked" />
		</li> 
  </ul>
            <button type="submit" class="oauthbutton"><img src="images/button.gif" alt="Create Alert" width="163" height="46" /></button>    
</form>
<div class="clear"> </div>
</div>
<div id="footer">
<p>powered by: <a href="http://www.twitter.com"><img src="images/twitter.gif" alt="twitter" border="0" /></a> <a href="http://www.planningalerts.com"><img src="images/planningalerts.gif" alt="Planning Alerts" border="0" /></a> built by: <a href="http://www.lichfielddc.gov.uk"><img src="images/ldc.gif" alt="Lichfield District Council" border="0" /></a> made pretty by <a href="http://www.lincoln.gov.uk"><img src="images/lincoln.gif" alt="City of Lincoln Council" border="0" /></a> and <a href="http://twitter.com/michaeldpollard">@MichaelDPollard</a></p>
</div>
</div>
<div id="boxes">
	<div id="dialog" class="window">
	<a href="#" class="close"><img src="images/close.gif" /></a>
		<h3>Automatic following</h3>
		<p>If you leave the 'Automatically follow twitterplan' box checked, you will be taken to the Twitter website to authorise us to set you to follow <a href="http://www.twitter.com/planbot">@planbot</a>, the account that we use to send alerts.</p>
		<p>Your details will be used only for this purpose and will not be stored or made visible to Twitterplan.</p>
		<p>If you'd rather not use this method, please uncheck the box. You will need to manually follow <a href="http://www.twitter.com/planbot">@planbot</a> in order to receive DMs.</p>
	<img class="bottom" src="images/modalbottom.gif" alt="" />
	</div>
	<div id="area" class="window">
	<a href="#" class="close"><img src="images/close.gif" /></a>
	<h3>Is my area covered?</h3>
	<p>Twitterplan covers the same councils as <a href="http://www.planningalerts.com">Planning Alerts</a>.</p> 
	<p>If your council is not covered, you can sign up anyway, and we will start sending alerts as soon as your council is added.</p>
	<h4>Councils currently covered</h4>
	<div id="councillist">
	<ul>
	<li>Aberdeenshire Council</li>
            <li>Allerdale Borough Council</li>
            <li>Alnwick District Council</li>
            <li>Amber Valley Borough Council</li>
            <li>Angus Council</li>

            <li>Argyll And Bute Council</li>
            <li>Arun District Council</li>
            <li>Aylesbury Vale District Council</li>
            <li>Babergh District Council</li>
            <li>Barnsley Metropolitan Borough Council</li>
            <li>Barrow Borough Council</li>

            <li>Basildon District Council</li>
            <li>Basingstoke and Deane Borough Council</li>
            <li>Bassetlaw District Council</li>
            <li>Bath and North East Somerset</li>
            <li>Bedford Borough Council</li>
            <li>Berwick-upon-Tweed Borough Council</li>

            <li>Bexley Council</li>
            <li>Birmingham City Council</li>
            <li>Blaby District Council</li>
            <li>Blackburn with Darwen Borough Council</li>
            <li>Blackpool Borough Council</li>
            <li>Bolsover District Council</li>

            <li>Bolton Metropolitan Borough Council</li>
            <li>Boston Borough Council</li>
            <li>Bracknell Forest Borough Council</li>
            <li>Bradford Metropolitan District Council</li>
            <li>Braintree District Council</li>
            <li>Breckland Council</li>

            <li>Brentwood Borough Council</li>
            <li>Bridgend County Borough Council</li>
            <li>Bridgnorth District Council</li>
            <li>Bristol City Council</li>
            <li>Broadland District Council</li>
            <li>Broads Authority</li>

            <li>Broxbourne Borough Council</li>
            <li>Broxtowe Borough Council</li>
            <li>Buckinghamshire County Council</li>
            <li>Bury Metropolitan Borough Council</li>
            <li>Caerphilly County Borough Council</li>
            <li>Cairngorms National Park</li>

            <li>Calderdale Council</li>
            <li>Cambridge City Council</li>
            <li>Cambridgeshire County Council</li>
            <li>Cannock Chase District Council</li>
            <li>Canterbury City Council</li>
            <li>Caradon District Council</li>

            <li>Carlisle City Council</li>
            <li>Carmarthenshire County Council</li>
            <li>Castle Point Borough Council</li>
            <li>Charnwood Borough Council</li>
            <li>Chelmsford Borough Council</li>
            <li>Cheltenham Borough Council</li>

            <li>Cherwell District Council</li>
            <li>Chester-le-Street District Council</li>
            <li>Chichester District Council</li>
            <li>Chiltern District Council</li>
            <li>Chorley Borough Council</li>
            <li>Christchurch Borough Council</li>

            <li>City of London</li>
            <li>City of York Council</li>
            <li>Colchester Borough Council</li>
            <li>Comhairle Nan Eilean Siar</li>
            <li>Conwy County Borough Council</li>
            <li>Corby Borough Council</li>

            <li>Cornwall County Council</li>
            <li>Coventry City Council</li>
            <li>Craven District Council</li>
            <li>Crewe and Nantwich Borough Council</li>
            <li>Cumbria County Council</li>
            <li>Cyngor Gwynedd Council</li>

            <li>Dacorum Borough Council</li>
            <li>Dartford Borough Council</li>
            <li>Daventry District Council</li>
            <li>Denbighshire County Council</li>
            <li>Derby City Council</li>
            <li>Doncaster Metropolitan Borough Council</li>

            <li>Dorset County Council</li>
            <li>Dudley Metropolitan Borough Council</li>
            <li>Dundee City Council</li>
            <li>Durham City Council</li>
            <li>Ealing Council</li>
            <li>Easington District Council</li>

            <li>East Cambridgeshire District Council</li>
            <li>East Devon District Council</li>
            <li>East Dorset District Council</li>
            <li>East Hampshire District Council</li>
            <li>East Hertfordshire District Council</li>
            <li>East Lindsey District Council</li>

            <li>East Lothian Council</li>
            <li>East Northamptonshire Council</li>
            <li>East Riding of Yorkshire Council</li>
            <li>East Staffordshire District Council</li>
            <li>Eastbourne Borough Council</li>
            <li>Eastleigh Borough Council</li>

            <li>Eden District Council</li>
            <li>Ellesmere Port and Neston Borough Council</li>
            <li>Elmbridge Borough Council</li>
            <li>Epping Forest District Council</li>
            <li>Epsom and Ewell Borough Council</li>
            <li>Exeter City Council</li>

            <li>Exmoor National Park</li>
            <li>Fareham Borough Council</li>
            <li>Fenland District Council</li>
            <li>Fife Council</li>
            <li>Flintshire County Council</li>
            <li>Forest Heath District Council</li>

            <li>Forest of Dean District Council</li>
            <li>Fylde Borough Council</li>
            <li>Gateshead Metropolitan Borough Council</li>
            <li>Gedling Borough Council</li>
            <li>Glasgow City Council</li>
            <li>Gloucester City Council</li>

            <li>Gloucestershire County Council</li>
            <li>Gosport Borough Council</li>
            <li>Gravesham Borough Council</li>
            <li>Great Yarmouth Borough Council</li>
            <li>Guildford Borough Council</li>
            <li>Halton Borough Council</li>

            <li>Hambleton District Council</li>
            <li>Hampshire County Council</li>
            <li>Harborough District Council</li>
            <li>Haringey Council</li>
            <li>Harlow Council</li>
            <li>Harrogate Borough Council</li>

            <li>Hart District Council</li>
            <li>Hartlepool Borough Council</li>
            <li>Hastings Borough Council</li>
            <li>Havant Borough Council</li>
            <li>Herefordshire Council</li>
            <li>Hertsmere Borough Council</li>

            <li>High Peak Borough Council</li>
            <li>Highland Council</li>
            <li>Hinckley and Bosworth Borough Council</li>
            <li>Horsham District Council</li>
            <li>Huntingdonshire District Council</li>
            <li>Isle of Wight Council</li>

            <li>Kennet District Council</li>
            <li>Kerrier District Council</li>
            <li>Kings Lynn and West Norfolk Borough Council</li>
            <li>Kingston upon Hull City Council</li>
            <li>Kirklees Council</li>
            <li>Knowsley Council</li>

            <li>Lake District National Park Authority</li>
            <li>Lancaster City Council</li>
            <li>Leeds City Council</li>
            <li>Leicestershire County Council</li>
            <li>Lewes District Council</li>
            <li>Lichfield District Council</li>

            <li>Lincoln City Council</li>
            <li>Lincolnshire County Council</li>
            <li>Liverpool City Council</li>
            <li>London Borough of Barking and Dagenham</li>
            <li>London Borough of Barnet</li>
            <li>London Borough of Brent</li>

            <li>London Borough of Bromley</li>
            <li>London Borough of Camden</li>
            <li>London Borough of Croydon</li>
            <li>London Borough of Enfield</li>
            <li>London Borough of Greenwich</li>
            <li>London Borough of Hackney</li>

            <li>London Borough of Hammersmith and Fulham</li>
            <li>London Borough of Harrow</li>
            <li>London Borough of Havering</li>
            <li>London Borough of Hillingdon</li>
            <li>London Borough of Hounslow</li>
            <li>London Borough of Islington</li>

            <li>London Borough of Lambeth</li>
            <li>London Borough of Lewisham</li>
            <li>London Borough of Merton</li>
            <li>London Borough Of Newham</li>
            <li>London Borough of Redbridge</li>
            <li>London Borough of Richmond upon Thames</li>

            <li>London Borough of Southwark</li>
            <li>London Borough of Sutton</li>
            <li>London Borough of Tower Hamlets</li>
            <li>Luton Borough Council</li>
            <li>Macclesfield Borough Council</li>
            <li>Maidstone Borough Council</li>

            <li>Maldon District Council</li>
            <li>Malvern Hills District Council</li>
            <li>Manchester City Council</li>
            <li>Mansfield District Council</li>
            <li>Medway Council</li>
            <li>Melton Borough Council</li>

            <li>Mendip District Council</li>
            <li>Mid Bedfordshire District Council</li>
            <li>Mid Devon District Council</li>
            <li>Mid Suffolk District Council</li>
            <li>Mid Sussex District Council</li>
            <li>Middlesbrough Borough Council</li>

            <li>Milton Keynes Council</li>
            <li>Mole Valley District Council</li>
            <li>Moray Council</li>
            <li>Neath Port Talbot County Borough Council</li>
            <li>New Forest District Council</li>
            <li>New Forest National Park</li>

            <li>Newcastle City Council</li>
            <li>Newcastle-under-Lyme Borough Council</li>
            <li>Newport City Council</li>
            <li>North Ayrshire Council</li>
            <li>North East Derbyshire District Council</li>
            <li>North East Lincolnshire Council</li>

            <li>North Hertfordshire District Council</li>
            <li>North Lincolnshire Council</li>
            <li>North Somerset Council</li>
            <li>North Tyneside Council</li>
            <li>North Warwickshire Borough Council</li>
            <li>North West Leicestershire District Council</li>

            <li>North Wiltshire District Council</li>
            <li>North Yorkshire County Council</li>
            <li>Northumberland County Council</li>
            <li>Norwich City Council</li>
            <li>Nottingham City Council</li>
            <li>Oadby and Wigston Borough Council</li>

            <li>Oldham Metropolitan Borough Council</li>
            <li>Olympic Delivery Authority</li>
            <li>Oswestry Borough Council</li>
            <li>Oxford City Council</li>
            <li>Pembrokeshire County Council</li>
            <li>Pendle Borough Council</li>

            <li>Perth and Kinross Council</li>
            <li>Peterborough City Council</li>
            <li>Poole Borough Council</li>
            <li>Portsmouth City Council</li>
            <li>Reading Borough Council</li>
            <li>Redditch Borough Council</li>

            <li>Reigate and Banstead Borough Council</li>
            <li>Renfrewshire Council</li>
            <li>Richmondshire District Council</li>
            <li>Rochdale Metropolitan Borough Council</li>
            <li>Rochford District Council</li>
            <li>Rother District Council</li>

            <li>Royal Borough of Kingston upon Thames</li>
            <li>Rugby Borough Council</li>
            <li>Rushmoor Borough Council</li>
            <li>Rutland County Council</li>
            <li>Ryedale District Council</li>
            <li>Salford City Council</li>

            <li>Sandwell Metropolitan Borough Council</li>
            <li>Scarborough Borough Council</li>
            <li>Scottish Borders Council</li>
            <li>Selby District Council</li>
            <li>Sevenoaks District Council</li>
            <li>Sheffield City Council</li>

            <li>Shetland Islands Council</li>
            <li>Shrewsbury and Atcham Borough Council</li>
            <li>Shropshire County Council</li>
            <li>Slough Borough Council</li>
            <li>Snowdonia National Park Authority</li>
            <li>Solihull Metropolitan Borough Council</li>

            <li>Somerset County Council</li>
            <li>South Bedfordshire District Council</li>
            <li>South Bucks District Council</li>
            <li>South Gloucestershire Council</li>
            <li>South Lakeland District Council</li>
            <li>South Norfolk Council</li>

            <li>South Northamptonshire Council</li>
            <li>South Oxfordshire District Council</li>
            <li>South Ribble Borough Council</li>
            <li>South Shropshire District Council</li>
            <li>South Somerset District Council</li>
            <li>South Staffordshire Council</li>

            <li>South Tyneside Council</li>
            <li>Southampton City Council</li>
            <li>Spelthorne Borough Council</li>
            <li>St Edmundsbury Borough Council</li>
            <li>St Helens Council</li>
            <li>Stafford Borough Council</li>

            <li>Staffordshire Moorlands District Council</li>
            <li>Stevenage Borough Council</li>
            <li>Stirling Council</li>
            <li>Stockport Metropolitan Borough Council</li>
            <li>Stockton-On-Tees Borough Council</li>
            <li>Stratford-on-Avon District Council</li>

            <li>Suffolk Coastal District Council</li>
            <li>Suffolk County Council</li>
            <li>Sunderland City Council</li>
            <li>Surrey Heath Borough Council</li>
            <li>Swansea City and County</li>
            <li>Swindon Borough Council</li>

            <li>Tamworth Borough Council</li>
            <li>Teignbridge District Council</li>
            <li>Tendring District Council</li>
            <li>Test Valley Borough Council</li>
            <li>Tewkesbury Borough Council</li>
            <li>The City of Edinburgh Council</li>

            <li>The Royal Borough of Kensington and Chelsea</li>
            <li>Three Rivers District Council</li>
            <li>Thurrock Borough Council</li>
            <li>Tonbridge and Malling Borough Council</li>
            <li>Torbay Council</li>
            <li>Torridge District Council</li>

            <li>Trafford Council</li>
            <li>Tunbridge Wells Borough Council</li>
            <li>Uttlesford District Council</li>
            <li>Vale of the White Horse District Council</li>
            <li>Vale Royal Borough Council</li>
            <li>Wakefield Metropolitan District Council</li>

            <li>Waltham Forest Council</li>
            <li>Wansbeck District Council</li>
            <li>Warrington Borough Council</li>
            <li>Watford Borough Council</li>
            <li>Waveney District Council</li>
            <li>Wealden District Council</li>

            <li>Wear Valley District Council</li>
            <li>Wellingborough Borough Council</li>
            <li>Welwyn-Hatfield District Council</li>
            <li>West Berkshire Council</li>
            <li>West Dorset District Council</li>
            <li>West Lancashire District Council</li>

            <li>West Oxfordshire District Council</li>
            <li>West Sussex County Council</li>
            <li>West Wiltshire District Council</li>
            <li>Westminster City Council</li>
            <li>Weymouth and Portland Borough Council</li>
            <li>Wiltshire County Council</li>

            <li>Winchester City Council</li>
            <li>Woking Borough Council</li>
            <li>Wolverhampton City Council</li>
            <li>Worcester City Council</li>
            <li>Worthing Borough Council</li>
            <li>Wycombe District Council</li>

            <li>Wyre Forest District Council</li>
	</ul>
	</div>
		<img class="bottom" src="images/modalbottom.gif" alt="" />
	</div>
 	<div id="mask"></div>
</div>
<style type='text/css'>@import url('http://s3.amazonaws.com/getsatisfaction.com/feedback/feedback.css');</style>
<script src='http://s3.amazonaws.com/getsatisfaction.com/feedback/feedback.js' type='text/javascript'></script>
<script type="text/javascript" charset="utf-8">
  var tab_options = {}
  tab_options.placement = "left";  // left, right, bottom, hidden
  tab_options.color = "#222"; // hex (#FF0000) or color (red)
  GSFN.feedback('http://getsatisfaction.com/twitterplan/feedback/topics/new?display=overlay&style=question', tab_options);
</script>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-511839-14");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>
